package com.ruoyi.system.service.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.entity.admin.AdminAccountingDB;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.sql.MyPageUtils;
import com.ruoyi.system.mapper.admin.AdminAccountingMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AdminAccountingService {

    @Resource
    private AdminAccountingMapper adminAccountingDBMapper;

    /**
     * 查询后台-记账
     *
     * @param id 后台-记账主键
     * @return 后台-记账
     */
    public AdminAccountingDB selectAdminAccountingDBById(Long id) {
        return adminAccountingDBMapper.selectById(id);
    }

    /**
     * 查询后台-记账列表
     *
     * @param adminAccountingDB 后台-记账
     * @return 后台-记账
     */
    public TableDataInfo selectAdminAccountingDBList(AdminAccountingDB adminAccountingDB) {

        LambdaQueryWrapper<AdminAccountingDB> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtils.isNotEmpty(adminAccountingDB.getTransactionType()), AdminAccountingDB::getTransactionType, adminAccountingDB.getTransactionType());
        wrapper.eq(ObjectUtils.isNotEmpty(adminAccountingDB.getCounterpartyType()), AdminAccountingDB::getCounterpartyType, adminAccountingDB.getCounterpartyType());
        wrapper.between(ObjectUtils.isNotEmpty(adminAccountingDB.getTotalAmountMax()) && ObjectUtils.isNotEmpty(adminAccountingDB.getTotalAmountMin()), AdminAccountingDB::getTotalAmount, adminAccountingDB.getTotalAmountMin(), adminAccountingDB.getTotalAmountMax());
        wrapper.between(ObjectUtils.isNotEmpty(adminAccountingDB.getCreatedAtMax()) && ObjectUtils.isNotEmpty(adminAccountingDB.getCreatedAtMin()), AdminAccountingDB::getCreatedAt, adminAccountingDB.getCreatedAtMin(), adminAccountingDB.getCreatedAtMax());
        wrapper.eq(ObjectUtils.isNotEmpty(adminAccountingDB.getIsActive()), AdminAccountingDB::getIsActive, adminAccountingDB.getIsActive());
        // 按照id倒叙
        wrapper.orderByDesc(AdminAccountingDB::getId);

        // 分页
        Page<AdminAccountingDB> pageParam = MyPageUtils.handlePageParam();
        Page<AdminAccountingDB> communityAreaDBPage = adminAccountingDBMapper.selectPage(pageParam, wrapper);
        return TableDataInfo.covert(communityAreaDBPage);

    }

    /**
     * 新增后台-记账
     *
     * @param adminAccountingDB 后台-记账
     * @return 结果
     */
    public int insertAdminAccountingDB(AdminAccountingDB adminAccountingDB) {
        return adminAccountingDBMapper.insert(adminAccountingDB);
    }

    /**
     * 修改后台-记账
     *
     * @param adminAccountingDB 后台-记账
     * @return 结果
     */
    public int updateAdminAccountingDB(AdminAccountingDB adminAccountingDB) {
        return adminAccountingDBMapper.updateById(adminAccountingDB);
    }

    /**
     * 批量删除后台-记账
     *
     * @param ids 需要删除的后台-记账主键
     * @return 结果
     */
//    public int deleteAdminAccountingDBByIds(Long[] ids) {
//        return adminAccountingDBMapper.deleteAdminAccountingDBByIds(ids);
//    }
//
//    /**
//     * 删除后台-记账信息
//     *
//     * @param id 后台-记账主键
//     * @return 结果
//     */
//    public int deleteAdminAccountingDBById(Long id) {
//        return adminAccountingDBMapper.deleteAdminAccountingDBById(id);
//    }
}
